//
//  ZFLandScapeControlView.m
//  ZFPlayer
//
// Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "XHLandScapeControlView.h"
#import "LessonDetailModel.h"
#if __has_include(<ZFPlayer/ZFPlayer.h>)
#import <ZFPlayer/ZFPlayerConst.h>
#else
#import "ZFPlayerConst.h"
#import "XHVideoMoreView.h"
#endif

@interface XHLandScapeControlView () <ZFSliderViewDelegate>
/// 顶部工具栏
@property (nonatomic, strong) UIView *topToolView;
/// 返回按钮
@property (nonatomic, strong) UIButton *backBtn;
/// 标题
@property (nonatomic, strong) UILabel *titleLabel;
/// 底部工具栏
@property (nonatomic, strong) UIView *bottomToolView;
/// 播放或暂停按钮
@property (nonatomic, strong) UIButton *playOrPauseBtn;
/// 播放的当前时间
@property (nonatomic, strong) UILabel *currentTimeLabel;
/// 滑杆
@property (nonatomic, strong) ZFSliderView *slider;
/// 视频总时间
@property (nonatomic, strong) UILabel *totalTimeLabel;

@property (nonatomic, assign) BOOL isShow;

// 倍率
@property (nonatomic,strong)UIButton *rateBtn;
// 护眼模式
@property (nonatomic,strong)UIButton *saveEyeBtn;
// 更多按钮
@property (nonatomic,strong)UIButton *moreBtn;
// 分享按钮
@property (nonatomic,strong)UIButton *shareBtn;
// 加入学习按钮
@property (nonatomic,strong)UIButton *afterClassBtn;
// 收藏按钮
@property (nonatomic,strong)UIButton *collectBtn;
// 加入学习
@property (nonatomic,strong)UIButton *addBtn;


@property (nonatomic,strong)UIView *coverView;
@property (nonatomic,strong)UIImageView *coverBrightnessView;
@property (nonatomic,strong)UIImageView *coverVolumeView;
@property (nonatomic,strong)UIImageView *coverProgressView;
@property (nonatomic,strong)UIImageView *coverFeedbackView;
@property (nonatomic,strong)UIImageView *coverAfterView;
@property (nonatomic,strong)UIImageView *coverRemoveView;
@property (nonatomic,strong)LessonDetailModel *itemModel;

@end

@implementation XHLandScapeControlView

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.topToolView];
        [self.topToolView addSubview:self.backBtn];
        [self.topToolView addSubview:self.titleLabel];
        [self.topToolView addSubview:self.moreBtn];
        [self.topToolView addSubview:self.shareBtn];
        [self.topToolView addSubview:self.afterClassBtn];
        [self.topToolView addSubview:self.addBtn];
        [self addSubview:self.bottomToolView];
        [self.bottomToolView addSubview:self.playOrPauseBtn];
        [self.bottomToolView addSubview:self.currentTimeLabel];
        
        [self.bottomToolView addSubview:self.slider];
        [self.bottomToolView addSubview:self.totalTimeLabel];
    
        
        [self.bottomToolView addSubview:self.rateBtn];
        [self.bottomToolView addSubview:self.saveEyeBtn];
       

        if (![[[NSUserDefaults standardUserDefaults]objectForKey:@"isFirstPlayVideo"]boolValue]) {
            [self addSubview:self.coverView];
            [self.coverView addSubview:self.coverBrightnessView];
            [self.coverView addSubview:self.coverVolumeView];
            [self.coverView addSubview:self.coverProgressView];
            [self.coverView addSubview:self.coverAfterView];
            [self.coverView addSubview:self.coverFeedbackView];
            [self.coverView addSubview:self.coverRemoveView];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeHelpView)];
            [self.coverRemoveView addGestureRecognizer:tap];
        }

        // 设置子控件的响应事件
        [self makeSubViewsAction];
        [self resetControlView];
        
        /// statusBarFrame changed
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutControllerViews) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat min_x = 0;
    CGFloat min_y = 0;
    CGFloat min_w = 0;
    CGFloat min_h = 0;
    CGFloat min_view_w = self.bounds.size.width;
    CGFloat min_view_h = self.bounds.size.height;
    
    CGFloat min_margin = 9;
    
    min_x = 0;
    min_y = 0;
    min_w = min_view_w;
    min_h = IPHONE_X ? 110 : 80;
    self.topToolView.frame = CGRectMake(min_x, min_y, min_w, min_h);

    min_x = (IPHONE_X && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: 15;
    if (@available(iOS 13.0, *)) {
        min_y = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ? 10 : (IPHONE_X ? 40 : 20);
    } else {
        min_y = (IPHONE_X && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 10: (IPHONE_X ? 40 : 20);
    }
    min_w = 40;
    min_h = 40;
    self.backBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
    
    min_x = self.backBtn.cl_right + 5;
    min_y = 0;
    min_w = min_view_w - min_x - 15 ;
    min_h = 30;
    self.titleLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
    self.titleLabel.cl_centerY = self.backBtn.cl_centerY;
    
    min_h = 100;
    min_x = 0;
    min_y = min_view_h - min_h;
    min_w = min_view_w;
    self.bottomToolView.frame = CGRectMake(min_x, min_y, min_w, min_h);
    min_x = (IPHONE_X && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: 15;
    min_y = 32;
    min_w = 30;
    min_h = 30;
   
    
    min_x = 16;
    min_y = 16;
    min_w = 62;
    min_h = 30;
    self.currentTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
//    self.currentTimeLabel.cl_centerY = self.playOrPauseBtn.cl_centerY;
    
    min_w = 62;
    min_x = self.bottomToolView.cl_width - min_w - ((IPHONE_X && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: min_margin);
    min_y = 16;
    min_h = 30;
    self.totalTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
//    self.totalTimeLabel.cl_centerY = self.currentTimeLabel.cl_centerY;
    
    min_x = self.currentTimeLabel.cl_right + 4;
    min_w = self.totalTimeLabel.cl_x - min_x - 4;
    min_h = 30;
    self.slider.frame = CGRectMake(min_x, min_y, min_w, min_h);
   
  
    
    min_w = 62;
    min_x = self.bottomToolView.cl_width - min_w - ((IPHONE_X && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: min_margin);
    min_h = 30;
    self.totalTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
    self.rateBtn.frame = CGRectMake(min_x, CGRectGetMaxY(self.currentTimeLabel.frame) + 5, 60, 20);
    self.saveEyeBtn.frame = CGRectMake(CGRectGetMinX(self.rateBtn.frame) - 100, CGRectGetMaxY(self.currentTimeLabel.frame) + 5 , 80, 20);
    
    
    min_w = 40;
    min_h = 40;
    if (@available(iOS 13.0, *)) {
         min_y = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ? 10 : (IPHONE_X ? 40 : 20);
     } else {
         min_y = (IPHONE_X && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 10: (IPHONE_X ? 40 : 20);
     }
    self.moreBtn.frame = CGRectMake(CGRectGetMinX(self.rateBtn.frame), min_y, min_w, min_h);
    self.shareBtn.frame = CGRectMake(CGRectGetMinX(self.moreBtn.frame) - 50, min_y, min_w, min_h);
    self.afterClassBtn.frame = CGRectMake(CGRectGetMinX(self.shareBtn.frame) - 50, min_y, min_w, min_h);
    self.addBtn.frame = CGRectMake(CGRectGetMinX(self.afterClassBtn.frame) - 100, min_y, 80, 20);
    self.addBtn.cl_centerY = self.moreBtn.cl_centerY;
    
    min_x = 32;
    min_y = CGRectGetMaxY(self.currentTimeLabel.frame);
    self.playOrPauseBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
    
    self.coverView.frame = CGRectMake(0, 0, min_view_w, min_view_h);
    
    CGSize progressImgSize = self.coverProgressView.image.size;
    
    self.coverProgressView.frame = CGRectMake(min_view_w/2 - progressImgSize.width/2, min_view_h/2 - 24, progressImgSize.width, progressImgSize.height);
    
    CGFloat margin = (min_view_w - 3 * progressImgSize.width)/4 - 16;
    
    self.coverBrightnessView.frame = CGRectMake(CGRectGetMinX(self.coverProgressView.frame) - margin - progressImgSize.width, min_view_h/2 - 24, progressImgSize.width, progressImgSize.height);
    
    self.coverVolumeView.frame = CGRectMake(CGRectGetMaxX(self.coverProgressView.frame) + margin, min_view_h/2 - 24, progressImgSize.width, progressImgSize.height);
    
    
    self.coverAfterView.cl_y = self.afterClassBtn.cl_y;
    self.coverAfterView.cl_centerX = self.afterClassBtn.cl_centerX - 25;
    
    self.coverFeedbackView.cl_y = self.moreBtn.cl_y;
    self.coverFeedbackView.cl_centerX = self.moreBtn.cl_centerX - 15;
    
    self.coverRemoveView.cl_right = min_view_w - 60;
    self.coverRemoveView.cl_bottom = min_view_h - 48;

    
    if (self.itemModel.paper == nil) {
        self.coverAfterView.hidden = YES;
        self.afterClassBtn.hidden = YES;
        self.addBtn.cl_x = CGRectGetMinX(self.shareBtn.frame) - 100;
        
    }
}

- (void)makeSubViewsAction {
    [self.backBtn addTarget:self action:@selector(backBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.playOrPauseBtn addTarget:self action:@selector(playPauseButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - action
- (void)rateMethod{
    if (self.rateBtnClickCallback) {
        self.rateBtnClickCallback();
    }
}
- (void)saveEyeMethod{
    
    self.isSaveStatus = !self.isSaveStatus;
    
    if (self.isSaveStatus) {
        [self.saveEyeBtn setTitleColor:[RPAppManager themColor] forState:UIControlStateNormal];
        self.saveEyeBtn.layer.borderColor = [RPAppManager themColor].CGColor;
    }else{
        [self cancelDarkStyle];
    }
    if (self.darkBtnClickCallback) {
        self.darkBtnClickCallback();
    }

}

- (void)moreMethod{
    if (self.moreBtnClickCallback) {
        self.moreBtnClickCallback();
    }
}
- (void)shareMethod{
    if (self.shareBtnClickCallback) {
        self.shareBtnClickCallback();
    }
}
- (void)afterMethod{
    if (self.afterBtnClickCallback) {
        self.afterBtnClickCallback();
    }
}
- (void)addMethod{
    if(self.addBtn.selected){
        return;
    }
    if (self.adddBtnClickCallback) {
        self.adddBtnClickCallback();
    }
}
- (void)removeAllCoverView{
    [self.coverView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.coverView removeFromSuperview];
}

- (void)removeHelpView{
    [[NSUserDefaults standardUserDefaults]setObject:@1 forKey:@"isFirstPlayVideo"];
    
    [self.coverView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.coverView removeFromSuperview];
    
    if (self.hideHelpViewClickCallback) {
        self.hideHelpViewClickCallback();
    }
}

- (void)layoutControllerViews {
    [self layoutIfNeeded];
    [self setNeedsLayout];
}

- (void)backBtnClickAction:(UIButton *)sender {

    if (self.backBtnClickCallback) {
        self.backBtnClickCallback();
    }
}

- (void)playPauseButtonClickAction:(UIButton *)sender {
    [self playOrPause];
}

/// 根据当前播放状态取反
- (void)playOrPause {
    self.playOrPauseBtn.selected = !self.playOrPauseBtn.isSelected;
    self.playOrPauseBtn.isSelected? [self.player.currentPlayerManager play]: [self.player.currentPlayerManager pause];
}

- (void)playBtnSelectedState:(BOOL)selected {
    self.playOrPauseBtn.selected = selected;
}

- (void)lockButtonClickAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.player.lockedScreen = sender.selected;
}

#pragma mark - ZFSliderViewDelegate

- (void)sliderTouchBegan:(float)value {
    self.slider.isdragging = YES;
}

- (void)sliderTouchEnded:(float)value {
    if (self.player.totalTime > 0) {
        self.slider.isdragging = YES;
        if (self.sliderValueChanging) self.sliderValueChanging(value, self.slider.isForward);
        @zf_weakify(self)
        [self.player seekToTime:self.player.totalTime*value completionHandler:^(BOOL finished) {
            @zf_strongify(self)
            if (finished) {
                self.slider.isdragging = NO;
                if (self.sliderValueChanged) self.sliderValueChanged(value);
                if (self.seekToPlay) {
                    [self.player.currentPlayerManager play];
                }
            }
        }];
    } else {
        self.slider.isdragging = NO;
        self.slider.value = 0;
    }
}

- (void)sliderValueChanged:(float)value {
    if (self.player.totalTime == 0) {
        self.slider.value = 0;
        return;
    }
    self.slider.isdragging = YES;
    NSString *currentTimeString = [ZFUtilities convertTimeSecond:self.player.totalTime*value];
    self.currentTimeLabel.text = currentTimeString;
    if (self.sliderValueChanging) self.sliderValueChanging(value,self.slider.isForward);
}

- (void)sliderTapped:(float)value {
    [self sliderTouchEnded:value];
    NSString *currentTimeString = [ZFUtilities convertTimeSecond:self.player.totalTime*value];
    self.currentTimeLabel.text = currentTimeString;
}

#pragma mark - public method

/// 重置ControlView
- (void)resetControlView {
    self.slider.value                = 0;
    self.slider.bufferValue          = 0;
    self.currentTimeLabel.text       = @"00:00";
    self.totalTimeLabel.text         = @"00:00";
    self.backgroundColor             = [UIColor clearColor];
    self.playOrPauseBtn.selected     = YES;
    self.titleLabel.text             = @"";
    self.topToolView.alpha           = 1;
    self.bottomToolView.alpha        = 1;
    self.isShow                      = NO;
}

- (void)showControlView {
    self.isShow                      = YES;
    if (self.player.isLockedScreen) {
        self.topToolView.cl_y        = -self.topToolView.cl_height;
        self.bottomToolView.cl_y     = self.cl_height;
    } else {
        self.topToolView.cl_y        = 0;
        self.bottomToolView.cl_y     = self.cl_height - self.bottomToolView.cl_height;
    }
    self.player.statusBarHidden      = NO;
    if (self.player.isLockedScreen) {
        self.topToolView.alpha       = 0;
        self.bottomToolView.alpha    = 0;
    } else {
        self.topToolView.alpha       = 1;
        self.bottomToolView.alpha    = 1;
    }
}

- (void)hideControlView {
    self.isShow                      = NO;
    self.topToolView.cl_y            = -self.topToolView.cl_height;
    self.bottomToolView.cl_y         = self.cl_height;
    
    self.player.statusBarHidden      = YES;
    self.topToolView.alpha           = 0;
    self.bottomToolView.alpha        = 0;
}

- (BOOL)shouldResponseGestureWithPoint:(CGPoint)point withGestureType:(ZFPlayerGestureType)type touch:(nonnull UITouch *)touch {
    
    if (![[[NSUserDefaults standardUserDefaults]objectForKey:@"isFirstPlayVideo"] boolValue]) {
        return NO;
    }
    
    CGRect sliderRect = [self.bottomToolView convertRect:self.slider.frame toView:self];
    if (CGRectContainsPoint(sliderRect, point)) {
        return NO;
    }
    if (self.player.isLockedScreen && type != ZFPlayerGestureTypeSingleTap) { // 锁定屏幕方向后只相应tap手势
        return NO;
    }
    return YES;
}

- (void)videoPlayer:(ZFPlayerController *)videoPlayer presentationSizeChanged:(CGSize)size {
    
}

- (void)videoPlayer:(ZFPlayerController *)videoPlayer currentTime:(NSTimeInterval)currentTime totalTime:(NSTimeInterval)totalTime {
    if (!self.slider.isdragging) {
        NSString *currentTimeString = [ZFUtilities convertTimeSecond:currentTime];
        self.currentTimeLabel.text = currentTimeString;
        NSString *totalTimeString = [ZFUtilities convertTimeSecond:totalTime];
        self.totalTimeLabel.text = totalTimeString;
        self.slider.value = videoPlayer.progress;
    }
}

- (void)videoPlayer:(ZFPlayerController *)videoPlayer bufferTime:(NSTimeInterval)bufferTime {
    self.slider.bufferValue = videoPlayer.bufferProgress;
}

- (void)showTitle:(NSString *)title fullScreenMode:(ZFFullScreenMode)fullScreenMode {
    self.titleLabel.text = title;
    self.player.orientationObserver.fullScreenMode = fullScreenMode;
}

/// 调节播放进度slider和当前时间更新
- (void)sliderValueChanged:(CGFloat)value currentTimeString:(NSString *)timeString {
    self.slider.value = value;
    self.currentTimeLabel.text = timeString;
    self.slider.isdragging = YES;
    [UIView animateWithDuration:0.3 animations:^{
        self.slider.sliderBtn.transform = CGAffineTransformMakeScale(1.2, 1.2);
    }];
}

/// 滑杆结束滑动
- (void)sliderChangeEnded {
    self.slider.isdragging = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.slider.sliderBtn.transform = CGAffineTransformIdentity;
    }];
}

#pragma mark - setter

- (void)setFullScreenMode:(ZFFullScreenMode)fullScreenMode {
    _fullScreenMode = fullScreenMode;
    self.player.orientationObserver.fullScreenMode = fullScreenMode;
}

#pragma mark - getter

- (UIView *)topToolView {
    if (!_topToolView) {
        _topToolView = [[UIView alloc] init];
        UIImage *image = [UIImage imageNamed:@"ZFPlayer_top_shadow"];
        _topToolView.layer.contents = (id)image.CGImage;
    }
    return _topToolView;
}

- (UIButton *)backBtn {
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"ZFPlayer_back_full"] forState:UIControlStateNormal];
    }
    return _backBtn;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:15.0];
    }
    return _titleLabel;
}

- (UIView *)bottomToolView {
    if (!_bottomToolView) {
        _bottomToolView = [[UIView alloc] init];
        UIImage *image = [UIImage imageNamed:@"ZFPlayer_bottom_shadow"];
        
        _bottomToolView.layer.contents = (id)image.CGImage;
    }
    return _bottomToolView;
}

- (UIButton *)playOrPauseBtn {
    if (!_playOrPauseBtn) {
        _playOrPauseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_playOrPauseBtn setImage:[UIImage imageNamed:@"ZFPlayer_play"] forState:UIControlStateNormal];
        [_playOrPauseBtn setImage:[UIImage imageNamed:@"ZFPlayer_pause"] forState:UIControlStateSelected];
    }
    return _playOrPauseBtn;
}

- (UILabel *)currentTimeLabel {
    if (!_currentTimeLabel) {
        _currentTimeLabel = [[UILabel alloc] init];
        _currentTimeLabel.textColor = [UIColor whiteColor];
        _currentTimeLabel.font = [UIFont systemFontOfSize:14.0f];
        _currentTimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _currentTimeLabel;
}

- (ZFSliderView *)slider {
    if (!_slider) {
        _slider = [[ZFSliderView alloc] init];
        _slider.delegate = self;
        _slider.maximumTrackTintColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.8];
        _slider.bufferTrackTintColor  = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];
        _slider.minimumTrackTintColor = [RPAppManager themColor];
        [_slider setThumbImage:[UIImage imageNamed:@"ZFPlayer_slider"] forState:UIControlStateNormal];
        _slider.sliderHeight = 2;
        [_slider startForward];
    }
    return _slider;
}

- (UILabel *)totalTimeLabel {
    if (!_totalTimeLabel) {
        _totalTimeLabel = [[UILabel alloc] init];
        _totalTimeLabel.textColor = [UIColor whiteColor];
        _totalTimeLabel.font = [UIFont systemFontOfSize:14.0f];
        _totalTimeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _totalTimeLabel;
}


- (UIButton *)rateBtn{
    if (!_rateBtn) {
        _rateBtn = [[UIButton alloc]init];
        [_rateBtn setTitle:@"1.0x" forState:UIControlStateNormal];
        [_rateBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rateBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _rateBtn.layer.cornerRadius = 5;
        _rateBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _rateBtn.layer.borderWidth = 0.5;
        _rateBtn.layer.masksToBounds = YES;
        _rateBtn.layer.masksToBounds = YES;
        [_rateBtn addTarget:self action:@selector(rateMethod) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rateBtn;
}

- (UIButton *)saveEyeBtn{
    if (!_saveEyeBtn) {
        _saveEyeBtn = [[UIButton alloc]init];
        [_saveEyeBtn setTitle:@"护眼模式" forState:UIControlStateNormal];
        [_saveEyeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _saveEyeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _saveEyeBtn.layer.cornerRadius = 5;
        _saveEyeBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _saveEyeBtn.layer.borderWidth = 0.5;
        _saveEyeBtn.layer.masksToBounds = YES;
        _saveEyeBtn.layer.masksToBounds = YES;
        [_saveEyeBtn addTarget:self action:@selector(saveEyeMethod) forControlEvents:UIControlEventTouchUpInside];
    }
    return _saveEyeBtn;
}
- (UIButton *)moreBtn{
    if (!_moreBtn) {
        _moreBtn = [[UIButton alloc]init];
        [_moreBtn addTarget:self action:@selector(moreMethod) forControlEvents:UIControlEventTouchUpInside];
        [_moreBtn setImage:[UIImage imageNamed:@"video_more_tag"] forState:UIControlStateNormal];
    }
    return _moreBtn;
}

- (UIButton *)shareBtn{
    if (!_shareBtn) {
        _shareBtn = [[UIButton alloc]init];
        [_shareBtn setImage:[UIImage imageNamed:@"video_share_tag"] forState:UIControlStateNormal];
        [_shareBtn addTarget:self action:@selector(shareMethod) forControlEvents:UIControlEventTouchUpInside];
    }
    return _shareBtn;
}

- (UIButton *)afterClassBtn{
    if (!_afterClassBtn) {
        _afterClassBtn = [[UIButton alloc]init];
        [_afterClassBtn setImage:[UIImage imageNamed:@"video_after_tag"] forState:UIControlStateNormal];
        [_afterClassBtn addTarget:self action:@selector(afterMethod) forControlEvents:UIControlEventTouchUpInside];
    }
    return _afterClassBtn;
}
- (UIButton *)addBtn{
    if (!_addBtn) {
        _addBtn = [[UIButton alloc]init];
        _addBtn.layer.borderWidth = 1;
        _addBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _addBtn.layer.cornerRadius = 4;
        [_addBtn setTitle:@"加入学习" forState:UIControlStateNormal];
        [_addBtn setTitle:@"已加入学习" forState:UIControlStateSelected];
        [_addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_addBtn addTarget:self action:@selector(addMethod) forControlEvents:UIControlEventTouchUpInside];
        _addBtn.titleLabel.font = font(12);
    }
    return _addBtn;
}

- (UIView *)coverView{
    if (!_coverView) {
        _coverView = [[UIView alloc]init];
        _coverView.backgroundColor = RGBA(0, 0, 0, 0.7);
    }
    return _coverView;
}

- (UIImageView *)coverBrightnessView{
    if (!_coverBrightnessView) {
        _coverBrightnessView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"video_change_left_tag"]];
    }
    return _coverBrightnessView;
}
- (UIImageView *)coverVolumeView{
    if (!_coverVolumeView) {
        _coverVolumeView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"video_change_right_tag"]];
    }
    return _coverVolumeView;
}
- (UIImageView *)coverProgressView{
    if (!_coverProgressView) {
        _coverProgressView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"video_change_progress_tag"]];
    }
    return _coverProgressView;
}
- (UIImageView *)coverFeedbackView{
    if (!_coverFeedbackView) {
        _coverFeedbackView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"video_change_feedback_tag"]];
    }
    return _coverFeedbackView;
}
- (UIImageView *)coverAfterView{
    if (!_coverAfterView) {
        _coverAfterView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"video_change_after_tag"]];
    }
    return _coverAfterView;
}
- (UIImageView *)coverRemoveView{
    if (!_coverRemoveView) {
        _coverRemoveView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_help_tag"]];
        _coverRemoveView.userInteractionEnabled = YES;
    }
    return _coverRemoveView;
}

#pragma mark - 自定义方法
- (void)updateAddBtnStatus{
    
    self.addBtn.selected = YES;
    
    [self.addBtn setTitleColor:[RPAppManager themColor] forState:UIControlStateNormal];
    self.addBtn.layer.borderColor = [RPAppManager themColor].CGColor;
    
    
}
- (void)updateRate:(CGFloat)rate{
    [self.rateBtn setTitle:[NSString stringWithFormat:@"%@x",[NSNumber numberWithFloat:rate]] forState:UIControlStateNormal];
}
- (void)cancelDarkStyle{
    
    self.isSaveStatus = NO;
    
    [self.saveEyeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.saveEyeBtn.layer.borderColor = [UIColor whiteColor].CGColor;

}
- (void)bindModel:(LessonDetailModel *)itemModel{
    self.itemModel = itemModel;
}

@end
